package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeSensorType;
import com.codegeek.project.slope.service.ISlopeSensorTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 传感器类型Controller
 *
 * @author codegeek
 * @date 2020-02-20
 */
@RestController
@RequestMapping("/slope/sensorType")
@Api(value = "传感器类型Controller", tags = {"传感器类型操作接口"})
public class SlopeSensorTypeController extends BaseController {
    @Autowired
    private ISlopeSensorTypeService slopeSensorTypeService;

    /**
     * 查询传感器类型列表
     */
    @ApiOperation("查询传感器类型列表")
    @GetMapping("/list")
    public TableDataInfo list(SlopeSensorType slopeSensorType) {
        startPage();
        List<SlopeSensorType> list = slopeSensorTypeService.selectSlopeSensorTypeList(slopeSensorType);
        return getDataTable(list);
    }

    /**
     * 导出传感器类型列表
     */
    @ApiOperation("导出传感器类型列表")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SlopeSensorType slopeSensorType) {
        List<SlopeSensorType> list = slopeSensorTypeService.selectSlopeSensorTypeList(slopeSensorType);
        ExcelUtil<SlopeSensorType> util = new ExcelUtil<SlopeSensorType>(SlopeSensorType.class);
        return util.exportExcel(list, "sensorType");
    }

    /**
     * 获取传感器类型详细信息
     */
    @ApiOperation("获取传感器类型详细信息")
    @GetMapping(value = "/getInfo/{sensorTypeId}")
    public AjaxResult getInfo(@PathVariable("sensorTypeId") Integer sensorTypeId) {
        return AjaxResult.success(slopeSensorTypeService.selectSlopeSensorTypeById(sensorTypeId));
    }

    /**
     * 新增传感器类型
     */
    @ApiOperation("新增传感器类型")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SlopeSensorType slopeSensorType) {
        return toAjax(slopeSensorTypeService.insertSlopeSensorType(slopeSensorType));
    }

    /**
     * 修改传感器类型
     */
    @ApiOperation("修改传感器类型")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SlopeSensorType slopeSensorType) {
        return toAjax(slopeSensorTypeService.updateSlopeSensorType(slopeSensorType));
    }

    /**
     * 删除传感器类型
     */
    @ApiOperation("删除传感器类型")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{sensorTypeIds}")
    public AjaxResult remove(@PathVariable Long[] sensorTypeIds) {
        return toAjax(slopeSensorTypeService.deleteSlopeSensorTypeByIds(sensorTypeIds));
    }
}
